<?php

namespace App\Admin\Controllers\User;

use App\Admin\Models\AdminPermission;
use Illuminate\Http\Request;
use App\Admin\Controllers\Controller;

class PermissionController extends Controller
{
    // 用户列表
    public function index()
    {
        $permissions = AdminPermission::query()->paginate(10);
        return view('admin.permission.index', compact('permissions'));
    }

    // 创建用户页面
    public function create()
    {
        return view('admin.permission.create');
    }

    // 创建用户行为
    public function store(Request $request)
    {
        // 验证
        $rules = [
            'name' => 'required|string|min:2',
            'description' => 'required|string|min:2',
        ];
        $this->validate($request, $rules);

        // 保存
        AdminPermission::query()->create($request->only('name', 'description'));

        // 渲染
        return redirect('/admin/permissions');
    }
}
